/**
 * Created by no1 on 2015/8/11.
 */
'use strict';
console.log('Load O2O: ' + module.id);
let F = require('./function');
let Dao = require('./dao');
let appConfigDispatcher = new Dao.appConfig();

function* api() {

}
exports.api = api;

/**
 * @todo 添加
 * @param Env
 */
api.add = function*(Env) {
    Env.I = yield F.Init(Env, [1]);
    if (Env.I.errors) {
        return F.returnMsg(400, Env.I.errors.msg, Env.I.errors.level);
    }
    let fields = Env.I;
    var ret = yield appConfigDispatcher.add(fields);
    if (ret.error == 1) return F.returnMsg(400, ret.msg, 3);
    return F.returnMsg(200, ret.msg, 3, ret.data);
};

/**
 * @todo更新
 * @param Env
 */
api.update = function*(Env) {
    Env.I = yield F.Init(Env, [1]);
    if (Env.I.errors) {
        return F.returnMsg(400, Env.I.errors.msg, Env.I.errors.level);
    }
    let fields = Env.I;
    var ret = yield appConfigDispatcher.update(fields);
    if (ret.error == 1) return F.returnMsg(400, ret.msg, 3);
    return F.returnMsg(200, ret.msg, 3, ret.data);
};

/**
 * @todo 详情
 * @param Env
 */
api.detail = function*(Env) {
    Env.I = yield F.Init(Env, [1]);
    if (Env.I.errors) {
        return F.returnMsg(400, Env.I.errors.msg, Env.I.errors.level);
    }
    let fields = Env.I;
    var ret = yield appConfigDispatcher.detail(fields);
    if (ret.error == 1) return F.returnMsg(400, ret.msg, 3);
    return F.returnMsg(200, ret.msg, 3, ret.data);
};